#version 330 core

in vec2 TexCoords;

uniform float Time;
uniform sampler2D image;
uniform vec4 outline_color;

out vec4 FragColor;
const float lineWidth = 3.0;

void main()
{
    float size_x = 1.0 / (float)(textureSize(image, 0).x) * lineWidth;
    float size_y = 1.0 / (float)(textureSize(image, 0).y) * lineWidth;
	vec4 imgColor = texture2D(image, TexCoords);
    
    float alpha = 8.0 * imgColor.a;
	alpha -= texture2D(image, TexCoords + vec2(size_x, 0.0)).a;
	alpha -= texture2D(image, TexCoords + vec2(-size_x, 0.0)).a;
	alpha -= texture2D(image, TexCoords + vec2(0.0, size_y)).a;
	alpha -= texture2D(image, TexCoords + vec2(0.0, -size_y)).a;
	
	alpha -= texture2D(image, TexCoords + vec2(size_x, size_y)).a;
	alpha -= texture2D(image, TexCoords + vec2(-size_x, size_y)).a;
	alpha -= texture2D(image, TexCoords + vec2(size_x, -size_y)).a;
	alpha -= texture2D(image, TexCoords + vec2(-size_x, -size_y)).a;
	
	vec4 color = mix(imgColor, outline_color, clamp(alpha, 0.0, 1.0));
    FragColor = vec4(color.rgb, clamp(alpha + imgColor.a, 0.0, 1.0));
}
